<template>
  <!-- 组织管理/编辑信息 -->
  <div class="sub-menu">
    <el-dialog
      title="编辑信息"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form
        :model="formData"
        :rules="rules"
        label-position="right"
        label-width="120px"
        ref="editNodeForm"
      >
        <el-form-item label="组织名称" prop="orgName">
          <el-input v-model="formData.orgName" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item
          label="组织分类"
          prop="orgType"
          v-if="curSelectNode.orgType !== 1"
        >
          <el-select
            v-model="formData.orgType"
            placeholder="请选择"
            style="width:100%;"
          >
            <el-option
              v-for="item in orgTypeArr"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="描述">
          <el-input
            v-model="formData.orgDesc"
            clearable
            type="textarea"
            maxlength="80"
            placeholder="描述"
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose()">取 消</el-button>
        <el-button type="primary" @click="submitForm">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {hasIn, cloneDeep} from 'lodash'
import {
  UcOrganizationUpdate // 批量增加岗位角色
} from '@const/api_staffCenter.js'
export default {
  components: {},
  data() {
    return {
      dialogVisible: false,
      formData: {
        id: '',
        orgName: '',
        orgType: '',
        orgDesc: ''
      },
      rules: {
        orgName: [{required: true, message: '请输入', trigger: 'blur'}],
        orgType: [{required: true, message: '请选择', trigger: 'blur'}]
      },
      curSelectNode: {},
      orgTypeArr: [
        {
          value: 3,
          label: '部门'
        },
        {
          value: 4,
          label: '岗位'
        }
      ],
      conpanyArr: []
    }
  },
  mounted() {},
  methods: {
    showDialog(curSelectNode) {
      this.curSelectNode = curSelectNode
      this.formData = cloneDeep(curSelectNode)
      this.dialogVisible = true
    },
    handleClose(done) {
      this.$refs['editNodeForm'].resetFields()
      this.dialogVisible = false
    },
    submitForm() {
      this.$refs.editNodeForm.validate(valid => {
        if (valid) {
          let params = {
            id: this.formData.id,
            orgName: this.formData.orgName,
            orgType: this.formData.orgType,
            orgDesc: this.formData.orgDesc
          }
          this.$axios({
            url: UcOrganizationUpdate,
            method: 'post',
            data: params
          })
            .then(res => {
              if (res.data.msg === 'ok') {
                this.$message.success('编辑成功')
                this.$emit('initial')
              }
            })
            .finally(() => {
              this.dialogVisible = false
            })
        }
      })
    }
  }
}
</script>
<style lang="less"></style>
